<?php

/**
 * OntoWiki model import template
 *
 * @author Norman Heino <norman.heino@gmail.com>
 * @version $Id: create.phtml 3891 2009-08-02 05:35:02Z pfrischmuth $
 */

?>
<?php if (!isset($this->errorFlag) || $this->errorFlag === false): ?>
<input type="hidden" name="referer" value="<?php echo $this->referer ?>">
<fieldset>
    <legend><?php echo $this->title ?></legend>
    <div>
        <?php if ($this->has('modelTitle')): ?>
            <label><?php echo $this->_('Knowledge Base') ?></label>
            <input type="text" class="text" value="<?php echo $this->modelTitle ?>" readonly="readonly" />
            <input type="hidden" name="modelUri" value="<?php echo $this->modelUri ?>" />
        <?php else: ?>
            <label for="model-input"><?php echo $this->_('Knowledge Base URI') ?></label>
            <?php if (!empty($this->modelUri)): ?>
                <?php // if model URI is set, don't allow it to be changed ?>
                <input type="text" class="text" id="model-input" name="modelUri" value="<?php echo $this->modelUri ?>" readonly="readonly" />
            <?php else: ?>
                <input type="text" class="text" id="model-input" name="modelUri" />
            <?php endif; ?>
            <br class="clearall" />
        <?php endif; ?>
    </div>

    <div>
        <?php if (empty($this->modelUri)): ?>
            <?php // if model URI is set, don't allow empty model creation ?>
            <label class="checkboxradio" for="r01">
                <input type="radio" class="radio" name="activeForm" id="r01" value="empty" />
                <?php echo $this->_('Create an Empty Knowledge Base') ?>
            </label>
            <br class="clearall" />
        <?php endif; ?>
        
        <?php if (ini_get('allow_url_fopen')): ?>
            <label class="checkboxradio" for="r02">
                <input type="radio" class="radio" name="activeForm" id="r02" value="import" />
                <?php echo $this->_('Import From the Web') ?>
            </label>
            <br class="clearall" />
        <?php endif; ?>
        
        <label class="checkboxradio" for="r03">
            <input type="radio" class="radio" name="activeForm" id="r03" value="upload" />
            <?php echo $this->_('Upload a File') ?>
        </label>
        <br class="clearall" />
        
        <label class="checkboxradio" for="r04">
            <input type="radio" class="radio" name="activeForm" id="r04" value="paste" />
            <?php echo $this->_('Paste Source') ?>
        </label>
        <br class="clearall" />
    </div>
    
    <?php if (empty($this->modelUri)): ?>
        <?php // if model URI is set, don't allow empty model creation ?>
        <!-- empty model -->
        <fieldset class="activeForm" id="empty">
            <legend><?php echo $this->_('Create an Empty Knowledge Base') ?></legend>
            <div>
                <label for="base-input"><?php echo $this->_('Base URI') ?></label>
                <input type="text" class="text" id="base-input" name="baseUri" value="<?php echo $this->baseUri ?>" />
                <br class="clearall" />
            </div>
            <div>
                <label for="type-select"><?php echo $this->_('Type') ?></label>
                <select name="type" id="type-select">
                    <option value="owl" selected="selected">OWL</option>
                    <!--option value="rdfs">RDF(S)</option-->
                </select>
                <br class="clearall" />
            </div>
        </fieldset>
    <?php endif; ?>

    <!-- web import -->
    <?php if (ini_get('allow_url_fopen')): ?>
        <fieldset class="activeForm" id="import">
            <legend><?php echo $this->_('Import From the Web') ?></legend>
            <div>
                <p class="messagebox info">
                    <?php echo $this->_('Enter the URL where the model should be downloaded from. If you leave the field empty the model URI will be used.') ?>
                </p>
                <label for="location-input"><?php echo $this->_('Location') ?></label>
                <input type="text" class="text" id="location-input" name="location" />
                <br class="clearall"/>
            </div>
        </fieldset>
    <?php endif; ?>

    <!-- file upload -->
    <fieldset class="activeForm" id="upload">
        <legend><?php echo $this->_('Upload a File') ?></legend>
        <div>
        <label for="filetype-upload-select"><?php echo $this->_('File Type') ?></label>
        <select name="filetype-upload" id="filetype-upload-select">
            <option value="auto"><?php echo $this->_('Autodetect') ?></option>
            <?php foreach ($this->supportedFormats as $key => $name): ?>
                <option value="<?php echo $key ?>"><?php echo $name ?></option>
            <?php endforeach; ?>
        </select>
        <br class="clearall" />
        </div>
        <div>
            <label for="file-input">
                <?php echo sprintf($this->_('File (max. %1$sB)'), preg_replace('/([kMG])/', ' $1', ini_get('upload_max_filesize'))) ?>
            </label>
            <input type="file" id="file-input" name="source" />
            <br class="clearall" />
        </div>
    </fieldset>

    <!-- source paste -->
    <fieldset class="activeForm" id="paste">
        <legend><?php echo $this->_('Paste Source') ?></legend>
        <div>
            <label for="filetype-paste-select"><?php echo $this->_('Format') ?></label>
            <select name="filetype-paste" id="filetype-paste-select">
                <?php foreach ($this->supportedFormats as $key => $name): ?>
                    <option value="<?php echo $key ?>"><?php echo $name ?></option>
                <?php endforeach; ?>
            </select>
            <br class="clearall" />
            <label for="code-input"><?php echo $this->_('Source Code') ?></label>
            <textarea class="code-input" name="paste"></textarea>
            <br class="clearall">
        </div>
    </fieldset>
</fieldset>

<script type="text/javascript">
    toggleSubForm = function() {
    	var selValue = $(this).val();
    	var selName  = $(this).attr('name');
    	
    	// hide all others
        $('fieldset.' + selName + ':not(#' + selValue + ')').hide();
        $('fieldset.' + selName).css('display', 'none');
    	
    	// show the one selected
    	$('fieldset#' + selValue).fadeIn(effectTime);
    }
    
    $(document).ready(function() {
        $('input[name=activeForm]').click(toggleSubForm);
        
        // init form
        $('fieldset.activeForm:not(#<?php echo $this->activeForm ?>)').hide();
        $('input.radio[value=<?php echo $this->activeForm ?>]').attr('checked','checked');
        
        // propagate model URI on change to base URI input
        $('input#model-input').change(function() {
            if ($.trim($('input#location-input').val()) == '') {
                $('input#location-input').val($(this).val());
            }
        })
    });
</script>
<?php endif; ?>